//
//  UIcolor+Add.swift
//  HHSwift
//
//  Created by qk-huahong on 2019/6/19.
//  Copyright © 2019 huahong. All rights reserved.
//

import Foundation
extension UIColor{

//    static func color(withHexString hexStr:String) -> UIColor?{
//        CGFloat r, g, b, a;
//        if (hexStrToRGBA(hexStr, &r, &g, &b, &a)) {
//            return [UIColor colorWithRed:r green:g blue:b alpha:a];
//        }
//        return nil;
//    }
//
//    static BOOL hexStrToRGBA(NSString *str,
//    CGFloat *r, CGFloat *g, CGFloat *b, CGFloat *a) {
//    str = [[str stringByTrim] uppercaseString];
//    if ([str hasPrefix:@"#"]) {
//    str = [str substringFromIndex:1];
//    } else if ([str hasPrefix:@"0X"]) {
//    str = [str substringFromIndex:2];
//    }
//
//    NSUInteger length = [str length];
//    //         RGB            RGBA          RRGGBB        RRGGBBAA
//    if (length != 3 && length != 4 && length != 6 && length != 8) {
//    return NO;
//    }
//
//    //RGB,RGBA,RRGGBB,RRGGBBAA
//    if (length < 5) {
//    *r = hexStrToInt([str substringWithRange:NSMakeRange(0, 1)]) / 255.0f;
//    *g = hexStrToInt([str substringWithRange:NSMakeRange(1, 1)]) / 255.0f;
//    *b = hexStrToInt([str substringWithRange:NSMakeRange(2, 1)]) / 255.0f;
//    if (length == 4)  *a = hexStrToInt([str substringWithRange:NSMakeRange(3, 1)]) / 255.0f;
//    else *a = 1;
//    } else {
//    *r = hexStrToInt([str substringWithRange:NSMakeRange(0, 2)]) / 255.0f;
//    *g = hexStrToInt([str substringWithRange:NSMakeRange(2, 2)]) / 255.0f;
//    *b = hexStrToInt([str substringWithRange:NSMakeRange(4, 2)]) / 255.0f;
//    if (length == 8) *a = hexStrToInt([str substringWithRange:NSMakeRange(6, 2)]) / 255.0f;
//    else *a = 1;
//    }
//    return YES;
//    }

  static  func randomColor() -> UIColor {
      
        //drand48 返回服从均匀分布的·[0.0, 1.0) 之间的 double 型随机数
        return UIColor(red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1.0)

        // let color:UIColor = UIColor(displayP3Red: CGFloat(arc4random_uniform(256))/255.0, green: CGFloat(arc4random_uniform(256))/255.0, blue: CGFloat(arc4random_uniform(256))/255.0, alpha: 1.0)
    }
}




